<!-- 修改菜单 -->
<div class="layuimini-main">
    <div class="layui-form layuimini-form">
		
		<!-- 隐藏ID -->
		<input type="hidden" name="menuId" />
		
        <div class="layui-form-item">
            <label class="layui-form-label required"> 菜单名称 </label>
            <div class="layui-input-block">
                <input type="text" name="menuName" lay-verify="menuName" class="layui-input" />
			</div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label required"> 菜单路径 </label>
            <div class="layui-input-block">
                <input type="text" name="url" lay-verify="url" class="layui-input">
            </div>
        </div>
        
		<div class="layui-form-item">
		    <label class="layui-form-label required"> 菜单类型 </label>
		    <div class="layui-input-block">
		        <input type="radio" name="type" value="item" title="菜单" />
		        <input type="radio" name="type" value="folder" title="文件夹" />
		    </div>
		</div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label required"> 上级菜单 </label>
		    <div class="layui-input-block">
		        <select name="pid" lay-filter="pid">
				</select>
		    </div>
		</div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label"> 备注 </label>
		    <div class="layui-input-block">
		        <input type="text" name="remark" lay-verify="remark" class="layui-input"  />
		    </div>
		</div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save"> 保存 </button>
            </div>
        </div>
		
    </div>
</div>



<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/paigusu.min.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'layer', 'layarea'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
			layarea = layui.layarea,
            $ = layui.$;
		
        // 初始化表单，要加上，不然刷新部分组件可能会不加载
        //form.render();
		
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
		
		//自定义验证规则
		form.verify({
			//第一种写法
		    menuName: function (value, item) {	//value控件值，item表单DOM对象
		        if (value.length == 0) {
		            return '用户名不能为空';
		        }
		    },
			url:function(value,item){
				if(value.length==0){
					return "路径不能为空";
				}
			}
			//第二种写法
			// url: [/^[a-zA-Z0-9_-]{6,16}$/, '密码必须在6~16位']
			//sex:[/^正则表达式$/, '弹出消息']
		});
		
		
        //监听保存按钮事件
        form.on('submit(save)', function(data) {
			//获得表单数据
			var formData = data.field;
		
			//处理表单数据
			// var postData = {
			// 	'menuId': formData.menuId,
			// 	'menuName': formData.menuName
			// }
			
			//通过ajax请求后端接口，并提交数据
			$.ajax({
				url : 'http://localhost:8006/sccMenu',
				type: 'put',
				data: JSON.stringify(formData),
				contentType:'application/json;charset=UTF-8',
				success: function(result){	//后端响应成功回调函数
					//刷新页面
					table.reload('menuManagementTable');
				},
				error:function(result){
					//刷新页面
					table.reload('menuManagementTable');
				}
			});
			//关闭弹出层
			layer.close(parentIndex);
            return false;
        });
    });
</script>